package org.windowkit.toolkit.widget.treetable.ui;

import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;

import javax.swing.JComponent;
import javax.swing.tree.AbstractLayoutCache;
import javax.swing.tree.TreePath;
import javax.swing.tree.VariableHeightLayoutCache;

import com.sun.java.swing.plaf.windows.WindowsTreeUI;

/**
 * This class is overriden to not draw the connecting lines on the tree. We need
 * to do this in the table UI so that we can span columns. We can't do this with
 * the UIManager because legacy trees would need to be fixed to draw lines. This
 * class also extends the default tree layout cache. Since we are putting the
 * node of each level in a seperate column we do not want the indent like a
 * normally drawn tree would have. Otherwise each level you went down the node
 * would be drawn further from the left edge of the table cell. We want the
 * nodes to be left aligned in the cell.
 *
 * @author Eric Lundin
 */
public class StretchTreeUI extends WindowsTreeUI {
	// @Override
	// protected boolean isLocationInExpandControl(TreePath path, int mouseX,
	// int mouseY) {
	// return super.isLocationInExpandControl(path, mouseX, mouseY);
	// }

	@Override
	@SuppressWarnings("unused")
	protected void paintHorizontalLine(final Graphics g, final JComponent c, final int y,
			final int left, final int right) {
	}

	@Override
	@SuppressWarnings("unused")
	protected void paintVerticalLine(final Graphics g, final JComponent c, final int x, final int top,
			final int bottom) {
	}

	@Override
	@SuppressWarnings("unused")
	protected void paintHorizontalPartOfLeg(final Graphics g, final Rectangle clipBounds,
			final Insets insets, final Rectangle bounds, final TreePath path, final int row,
			final boolean isExpanded, final boolean hasBeenExpanded, final boolean isLeaf) {
	}

	@Override
	@SuppressWarnings("unused")
	protected void paintVerticalPartOfLeg(final Graphics g, final Rectangle clipBounds,
			final Insets insets, final TreePath path) {
	}

	@Override
	protected AbstractLayoutCache createLayoutCache() {
		return new TreeTableLayoutCache();
	}


	class TreeTableLayoutCache extends VariableHeightLayoutCache {
		@Override
		public Rectangle getBounds(final TreePath path, final Rectangle placeIn) {
			Rectangle r = super.getBounds(path, placeIn);
			 if (r != null) {
				r.x = 0;
			}
			return r;
		}
	}

}
